package site.microkang.house.restful;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.microkang.house.common.ResponseParam;
import site.microkang.house.external.http.GovSocialInsuranceHttpService;
import site.microkang.house.model.dto.TalentIdentificationInfoDto;
import site.microkang.house.model.entity.TalentIdentificationInfoEntity;
import site.microkang.house.model.vo.TalentIdentificationInfoParamVo;
import site.microkang.house.service.TalentIdentificationInfoService;

import java.util.List;

/**
 * @author liukang
 * @date 2021/3/19 22:43
 */
@Api(description ="人才认定网页信息API")
@RestController
@RequestMapping(value = "/v1/talentIdentificationInfo")
public class TalentIdentificationInfoRestful {

    @Autowired
    private GovSocialInsuranceHttpService govSocialInsuranceHttpService;
    @Autowired
    private TalentIdentificationInfoService talentIdentificationInfoService;

    /**
     * 获取所有数据
     * @param dto
     * @return
     */
    @ApiOperation("人才认定网页信息列表")
    @PostMapping(value = "list")
    public ResponseParam<List<TalentIdentificationInfoDto>> list(@RequestBody(required = false) TalentIdentificationInfoDto dto) {
        List<TalentIdentificationInfoDto> dtos = talentIdentificationInfoService.selectList(dto);
        return new ResponseParam<>(200, "操作成功", dtos);
    }

    /**
     * 添加人社局链接
     * @param vo
     * @return
     */
    @ApiOperation("根据人社局网址解析保存")
    @PostMapping(value = "add")
    public ResponseParam<Boolean> add(@RequestBody TalentIdentificationInfoParamVo vo) {
        try {
            TalentIdentificationInfoEntity entity = govSocialInsuranceHttpService.socialInsurancePageAnalysis(vo.getSocialInsuranceUrl());
            int insert = talentIdentificationInfoService.insert(entity);
            return new ResponseParam<>(200, "操作成功", insert == 0);
        } catch (Exception e) {
            return new ResponseParam<>(500, e.getMessage());
        }
    }
}
